package com.hualan.sfzy.service.psyc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.PsycTestTitle;
import com.hualan.sfzy.mapper.psyc.PsycTestTitleMapper;
import com.hualan.sfzy.service.psyc.PsycTestTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PsycTestTitleServiceImpl implements PsycTestTitleService {
    @Autowired
    private PsycTestTitleMapper topicMapper;
    @Override
    public int countByTestId(Integer psyknoTest) {
        return topicMapper.countByTestId(psyknoTest);
    }

    @Override
    public List<PsycTestTitle> findWithOptionsByTestId(Integer psyknoTest) {
        return topicMapper.selectWithOptionsByTestId(psyknoTest);
    }

    @Override
    public int add(PsycTestTitle entity) {
        return topicMapper.insert(entity);
    }

    @Override
    public int edit(PsycTestTitle entity) {
        return topicMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return topicMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return topicMapper.deleteBatch(ids);
    }

    @Override
    public List<PsycTestTitle> find() {
        return topicMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, PsycTestTitle entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<PsycTestTitle> list=topicMapper.select(entity);
        PageInfo<PsycTestTitle> pageInfo=new PageInfo<>(list);
        Map<String,Object> map=new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public PsycTestTitle findById(Integer id) {
        return topicMapper.selectById(id);
    }
}
